package com.hai.udp;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.*;
import java.util.logging.Logger;

/**
 * fileDesc
 * Created by huanghp on 2020/3/26.
 * Email h1132760021@sina.com
 */
public class MyClient {
    public static void main(String[] args) {
        DatagramSocket s = null;
        try {
            s = new DatagramSocket();
            String coding = "UTF-8";  //GBK，UTF-8
            byte[] messageByte = new byte[0];
            String message = "this is a mes seng by huang";
            messageByte = message.getBytes(coding);
            InetSocketAddress serverAddress = new InetSocketAddress("192.168.2.6", 60894);
            DatagramPacket p = new DatagramPacket(messageByte, messageByte.length, serverAddress);
            s.send(p);
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Logger.getLogger("myclient").info("test logger");
        System.out.println("send success");
    }
}
